import {About,Start,Doc} from '../doc';
import {
  // Select,Table,Tooltip,Tree,
  Dialog,Accordion,Components,MessageBox,Test,
  Select,Listgroup,Tooltip,Spinner
} from '../components';
import {createRouter,createWebHashHistory} from 'vue-router';
const routes = [
  {
    path : "/doc",
    component : Doc,
    children: [
      {
        path: '',
        component: About
      },
      {
        path: 'about',
        component: About
      },
      {
        path: 'start',
        component: Start
      }
    ]
  },
  {
    path: '/components',
    component : Components,
    children: [
      {path: '',component: Dialog},
      {path: 'dialog',component: Dialog},
      {path: 'accordion',component: Accordion},
      {path: 'messageBox',component: MessageBox},
      {path: 'select',component: Select},
      {path: 'listgroup',component: Listgroup},
      {path: 'tooltip',component: Tooltip},
      {path: 'spinner',component: Spinner},
      {path: 'test',component: Test}
      // {path: 'select',component: Select},
      // {path: 'table',component: Table},
      
      // {path: 'tree',component: Tree}
    ]
  }
];
const router = createRouter({
  history: createWebHashHistory(),
  routes
});
router.beforeEach((to, from, next) => {
  const {matched,path} = to;
  if(matched.length === 0){
    for(let route of routes){
      if(path.indexOf(route.path) === 0){
        next({ path: route.path });
        return;
      }
    }
    //默认路由
    next({ path: '/doc/about' });
  }else{
    next();
  }
});
export default router;